#ifndef _RTROOT_H_
#define _RTROOT_H_

#include "RtObject.h"

#include <QHash>
#include <QMetaObject>
#include <QStringList>


class RtMainWindow;

/** The RtLab root object.

All RtObject are descendands of RtRoot.

RtRoot is a static object which can be accessed by RtObject::root().

\ingroup RtCore

*/
class RTLAB_BASE_EXPORT RtRoot : public RtObject
{
	Q_OBJECT
protected:

	RtMainWindow* mainWindow_;

	QObjectList errorSinks;
	critical_section errorSinkLock;

public:
	RtRoot(void);
	virtual ~RtRoot(void);

	void objectCreation(RtObject* obj, bool c);

	RtMainWindow* mainWindow() const { return mainWindow_; }
	void setMainWindow(RtMainWindow* m) { mainWindow_ = m; }

	void addErrorSink(QObject* s);
	void removeErrorSink(QObject* s);
    void postError(RtObject* obj, const RtErrorEntry& e);

    QString h5write(const QString& filename, const QString& comment);

    QString xml();

    void registerClass(const QMetaObject* metaObj);

public slots:

    //RtObject* getElementById(const QString& id);
    /** Create a RtObject with specified name and class.
      Use appendChild or insertBefore to get the new object in the
      RtLab framework.
    */
    RtObject* createObject(const QString& name, const QString& className);
    /// Return the names of registered object classes.
    QStringList objectClassNames();
    /// Serialize contents to a HDF5 file.
    void h5write(const QString& filename);
    /// Read object contents from HDF5 file.
    void h5read(const QString& filename);


private:
    typedef QHash<QString, const QMetaObject*> object_map_t;

    object_map_t object_map_;

};




#endif


